package com.xinqi.modules.exam.common.manager.impl;

import com.xinqi.modules.exam.common.manager.CommonClassManager;
import com.xinqi.modules.exam.common.mapper.CommonClassMapper;
import com.xinqi.modules.exam.common.mapper.dto.ClassBaseDTO;
import com.xinqi.modules.exam.common.mapper.dto.ClassStudentBaseDTO;
import com.xinqi.modules.user.user.dto.rsp.UserBaseInfoDO;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * @author linkai
 * @date 2023/7/15
 */
@Component
@RequiredArgsConstructor
public class CommonClassManagerImpl implements CommonClassManager {
    private final CommonClassMapper commonClassMapper;

    @Override
    public List<Long> findStudentIdByClassId(Long classId) {
        if (classId == null) {
            return Collections.emptyList();
        }
        return commonClassMapper.findStudentIdByClassId(classId);
    }

    @Override
    public List<Long> findUserIdByClassId(Long classId) {
        if (classId == null) {
            return Collections.emptyList();
        }
        return commonClassMapper.findUserIdByClassId(classId);
    }

    @Override
    public List<Long> findRelationShipAndTeacherIdByClassId(Long classId) {
        if (classId == null) {
            return Collections.emptyList();
        }
        return commonClassMapper.findRelationShipAndTeacherIdByClassId(classId);
    }

    @Override
    public List<ClassStudentBaseDTO> findStudentBaseByClassId(Long classId) {
        if (classId == null) {
            return Collections.emptyList();
        }
        return commonClassMapper.findStudentBaseByClassId(classId);
    }

    @Override
    public List<ClassStudentBaseDTO> findStudentBase(Long classId, List<Long> studentIds) {
        if (classId == null) {
            return Collections.emptyList();
        }
        return commonClassMapper.findStudentBase(classId, studentIds);
    }

    @Override
    public ClassBaseDTO findBaseByClassId(Long classId) {
        if (classId == null) {
            return null;
        }
        return commonClassMapper.findBaseByClassId(classId);
    }

    @Override
    public List<UserBaseInfoDO> findUserInfoByUserIds(List<Long> userIds) {
        if (CollectionUtils.isEmpty(userIds)) {
            return Collections.emptyList();
        }
        return commonClassMapper.findUserInfoByUserIds(userIds);
    }

    @Override
    public UserBaseInfoDO findUserInfoByUserId(Long userId) {
        return commonClassMapper.findUserInfoByUserId(userId);
    }

    @Override
    public String findChapterNameById(Long chapterId) {
        return commonClassMapper.findChapterNameById(chapterId);
    }
}
